<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <title>create_test_sourcelist &mdash; CMake 4.1.1 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=a2c47e09" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css?v=4d06bd55" />
    
    <script src="../_static/documentation_options.js?v=e6a937a4"></script>
    <script src="../_static/doctools.js?v=9bcbadda"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    
    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="define_property" href="define_property.html" />
    <link rel="prev" title="cmake_instrumentation" href="cmake_instrumentation.html" />
 

  </head><body>
    <input id="sidebar-check" type="checkbox" />
    <label id="sidebar-overlay" for="sidebar-check"></label>



    <div class="related relbar1" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="define_property.html" title="define_property"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="cmake_instrumentation.html" title="cmake_instrumentation"
             accesskey="P">previous</a> |</li>
  <li>
    <label class="sidebar-toggle" for="sidebar-check"></label>
  </li>
  <li class="rootlink">
    <img src="../_static/cmake-logo-16.png" width="16" height="16" alt=""/>
    <a href="https://cmake.org/">CMake 4.1.1</a>
    <span class="reldelim1"> &#187;</span>
  </li>
  <li>
    <a href="../index.html">Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-commands.7.html" accesskey="U">cmake-commands(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">create_test_sourcelist</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="create-test-sourcelist">
<span id="command:create_test_sourcelist"></span><h1>create_test_sourcelist<a class="headerlink" href="#create-test-sourcelist" title="Link to this heading">¶</a></h1>
<p>Create a test driver program that links together many small tests into a
single executable.  This is useful when building static executables with
large libraries to shrink the total required size.</p>
<dl class="cmake signature">
<dt class="sig sig-object cmake" id="original">
<span class="code cmake highlight sig-name descname"><span class="nf"><span class="pre">create_test_sourcelist(</span></span><span class="nv"><span class="pre">&lt;sourceListName&gt;</span></span><span class="w"> </span><span class="nv"><span class="pre">&lt;driverName&gt;</span></span><span class="w"> </span><span class="nv"><span class="pre">&lt;test&gt;...</span></span><span class="w"> </span><span class="nv"><span class="pre">&lt;options&gt;...</span></span><span class="nf"><span class="pre">)</span></span></span><a class="headerlink" href="#original" title="Link to this definition">¶</a></dt>
<dd><p>Generate a test driver source file from a list of individual test sources
and provide a combined list of sources that can be built as an executable.</p>
<p>The options are:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">&lt;sourceListName&gt;</span></code></dt><dd><p>The name of a variable in which to store the list of source files needed
to build the test driver.  The list will contain the <code class="docutils literal notranslate"><span class="pre">&lt;test&gt;...</span></code> sources
and the generated <code class="docutils literal notranslate"><span class="pre">&lt;driverName&gt;</span></code> source.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 3.29: </span>The test driver source is listed by absolute path in the build tree.
Previously it was listed only as <code class="docutils literal notranslate"><span class="pre">&lt;driverName&gt;</span></code>.</p>
</div>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">&lt;driverName&gt;</span></code></dt><dd><p>Name of the test driver source file to be generated into the build tree.
The source file will contain a <code class="docutils literal notranslate"><span class="pre">main()</span></code> program entry point that
dispatches to whatever test is named on the command line.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">&lt;test&gt;...</span></code></dt><dd><p>Test source files to be added to the driver binary.  Each test source
file must have a function in it that is the same name as the file with the
extension removed.  For example, a <code class="docutils literal notranslate"><span class="pre">foo.cxx</span></code> test source might contain:</p>
<div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="n">foo</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">**</span><span class="w"> </span><span class="n">argv</span><span class="p">)</span>
</pre></div>
</div>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">EXTRA_INCLUDE</span> <span class="pre">&lt;header&gt;</span></code></dt><dd><p>Specify a header file to <code class="docutils literal notranslate"><span class="pre">#include</span></code> in the generated test driver source.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">FUNCTION</span> <span class="pre">&lt;function&gt;</span></code></dt><dd><p>Specify a function to be called with pointers to <code class="docutils literal notranslate"><span class="pre">argc</span></code> and <code class="docutils literal notranslate"><span class="pre">argv</span></code>.
The function may be provided in the <code class="docutils literal notranslate"><span class="pre">EXTRA_INCLUDE</span></code> header:</p>
<div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="n">function</span><span class="p">(</span><span class="kt">int</span><span class="o">*</span><span class="w"> </span><span class="n">pargc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">***</span><span class="w"> </span><span class="n">pargv</span><span class="p">)</span>
</pre></div>
</div>
<p>This can be used to add extra command line processing to each test.</p>
</dd>
</dl>
</dd></dl>

<p>Additionally, some CMake variables affect test driver generation:</p>
<dl class="cmake variable">
<dt class="sig sig-object cmake" id="variable:CMAKE_TESTDRIVER_BEFORE_TESTMAIN">
<span class="sig-name descname"><span class="pre">CMAKE_TESTDRIVER_BEFORE_TESTMAIN</span></span><a class="headerlink" href="#variable:CMAKE_TESTDRIVER_BEFORE_TESTMAIN" title="Link to this definition">¶</a></dt>
<dd><p>Code to be placed directly before calling each test's function.</p>
</dd></dl>

<dl class="cmake variable">
<dt class="sig sig-object cmake" id="variable:CMAKE_TESTDRIVER_AFTER_TESTMAIN">
<span class="sig-name descname"><span class="pre">CMAKE_TESTDRIVER_AFTER_TESTMAIN</span></span><a class="headerlink" href="#variable:CMAKE_TESTDRIVER_AFTER_TESTMAIN" title="Link to this definition">¶</a></dt>
<dd><p>Code to be placed directly after the call to each test's function.</p>
</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="cmake_instrumentation.html"
                          title="previous chapter">cmake_instrumentation</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="define_property.html"
                          title="next chapter">define_property</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/command/create_test_sourcelist.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="define_property.html" title="define_property"
             >next</a> |</li>
        <li class="right" >
          <a href="cmake_instrumentation.html" title="cmake_instrumentation"
             >previous</a> |</li>
  <li>
    <label class="sidebar-toggle" for="sidebar-check"></label>
  </li>
  <li class="rootlink">
    <img src="../_static/cmake-logo-16.png" width="16" height="16" alt=""/>
    <a href="https://cmake.org/">CMake 4.1.1</a>
    <span class="reldelim1"> &#187;</span>
  </li>
  <li>
    <a href="../index.html">Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-commands.7.html" >cmake-commands(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">create_test_sourcelist</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
    &#169; Copyright 2000-2025 Kitware, Inc. and Contributors.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
    </div>
<script type="text/javascript">
(function() {
  "use strict";
  const hide = () => document.getElementById("sidebar-check").checked = false;
  addEventListener("keydown", e => (e.key === "Escape") && hide());
  addEventListener("click", e => (e.target.tagName === "A") && hide());
  addEventListener("hashchange", hide)
})();
</script>
  </body>
</html>